/***************************************************************************
 创建者：华磊
 开始时间：         : 2020.12.08
 copyright            : (C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
 *   运动指令属性编辑视窗
*                                                                         *
 ***************************************************************************/
#include "motioninstructiondelegate.h"
#include <QDebug>
#include "../../CommunicateDelegate/filedata.h"
#include "hmicommondefine.h"

extern FileData fileData;

MotionInstructionDelegate::MotionInstructionDelegate(GlobalData *globalDataIn,
                                                     MoveOperation *moveOperationIn,
                                                     GlobalData *ioDataIn,QWidget *parent):
    QObject(parent)
{
    //motionInstructionView = new MotionInstructionView;
    globalData = globalDataIn;
    moveOperation = moveOperationIn;
    ioData=ioDataIn;
}

void MotionInstructionDelegate::initialView()
{
    motionInstructionView->motionInstruction = "J P [1] 100% FINE //";
    motionInstructionView->instructionType = "J";
    motionInstructionView->cInstruction = "C";
    motionInstructionView->instructionTypeFlag = E_MOTION_J;
    motionInstructionView->positionTypeFlag = 0;
    motionInstructionView->positionIndexStr = "1";
    motionInstructionView->instructionRate = 100;
    motionInstructionView->rateUnit = "%";
    motionInstructionView->rateUnitTypeFlag = E_RATE_PERCENT;
    motionInstructionView->instructionFixedPositionType = "FINE";
    motionInstructionView->fixedPositionTypeFlag = 0;
    motionInstructionView->cntValue = 50;

    motionInstructionView->lockBtnText = tr("点已解锁");
    motionInstructionView->lockBtnPicture = "color: rgb(255, 255, 255); border-width:0px;border-style:outset;image: url(/agvwork/AgvHmi/baseBag/hmiProject/resources/hmiController/resources/instruction/MotionInstructionRes/empty_n.png);";

    motionInstructionView->isUseDiSkip = 0;
    motionInstructionView->diIndex = "1";
    motionInstructionView->labelIndex = "1";
    motionInstructionView->diInstruction = "DI";
    motionInstructionView->diSwitch = "ON";
    motionInstructionView->diSwitchFlag = 0;

    motionInstructionView->wjntFlag = 0;
    motionInstructionView->incFlag = 0;
    motionInstructionView->accFlag = 0;
    motionInstructionView->offsetFlag = 0;
    motionInstructionView->toolOffsetFlag = 0;
    motionInstructionView->evFlag = 0;
    motionInstructionView->pthFlag = 0;

    motionInstructionView->wjntInstruction = "Wjnt";
    motionInstructionView->incInstruction  = "INC";
    motionInstructionView->accInstruction = "ACC";
    motionInstructionView->accValue = 0;
    motionInstructionView->offsetInstruction = "Offset";
    motionInstructionView->offsetPrIndex = "1";
    motionInstructionView->toolOffsetInstruction = "Tool_Offset";
    motionInstructionView->toolOffsetPrIndex = "1";
    motionInstructionView->evInstruction = "EV";
    motionInstructionView->evValue = 1;
    motionInstructionView->pthInstruction = "PTH";

    motionInstructionView->pointProMo.jointFlag = 0;
    motionInstructionView->pointProMo.pointNum = 0;
    motionInstructionView->pointProMo.groupNum = 0;
    motionInstructionView->pointProMo.ufValue = 0;
    motionInstructionView->pointProMo.utValue = 0;
    motionInstructionView->pointProMo.configString = "";
    motionInstructionView->pointProMo.configInt.clear();
    motionInstructionView->pointProMo.configInt.push_back(0);
    motionInstructionView->pointProMo.positionValue.clear();
    motionInstructionView->pointProMo.positionValue.push_back(0);

    //motionInstructionView->updateView();
}

void MotionInstructionDelegate::changeLanguage(int language)
{
    if(1 == language)
    {
        translator.load("/agvwork/AgvHmi/baseBag/hmiProject/language/motionDelEnglishLan.qm");
        qApp->installTranslator(&translator);
    }
    else
    {
        qApp->removeTranslator(&translator);
    }
}

void MotionInstructionDelegate::finishEditInstructionSlot()
{
    motionInstructionView->getInput();


    if(EM_INSTRUCTION_NORMAL == motionInstructionView->instructionMainFlag)
    {
        if(E_MOTION_J == motionInstructionView->instructionTypeFlag)
        {
            motionInstructionView->instructionType = "J";
        }
        else if(E_MOTION_L == motionInstructionView->instructionTypeFlag)
        {
            motionInstructionView->instructionType = "L";
        }
        else if(E_MOTION_A == motionInstructionView->instructionTypeFlag)
        {
            motionInstructionView->instructionType = "A";
        }
        else if(E_MOTION_C == motionInstructionView->instructionTypeFlag)
        {


            motionInstructionView->cInstruction = "C " + motionInstructionView->positionTypeStr
                    + "[" + motionInstructionView->positionIndexAddressStr + "]";

            if(1 == motionInstructionView->offsetFlag)
            {
                QString str = " Offset,";
                motionInstructionView->offsetInstruction = str + "PR" + "[" + motionInstructionView->offsetPrIndex + "]";
                motionInstructionView->cInstruction += motionInstructionView->offsetInstruction ;
            }
            if(1 == motionInstructionView->toolOffsetFlag)
            {
                QString str = " Tool_Offset,";
                motionInstructionView->toolOffsetInstruction = str + "PR" + "[" + motionInstructionView->toolOffsetPrIndex + "]";
                motionInstructionView->cInstruction += motionInstructionView->toolOffsetInstruction ;
            }
            motionInstructionView->cInstruction = motionInstructionView->cInstruction + "; "
                    + "//" + motionInstructionView->moIns.comment;
        }
        else if(E_MOTION_C2 == motionInstructionView->instructionTypeFlag)
        {
            motionInstructionView->instructionType = "  ";
        }
    }
    else//stamp样式
    {
        if(EM_INSTRUCTION_TYPE_F == motionInstructionView->instructionStampTypeFlag)
        {
            motionInstructionView->instructionType = "F";
        }
        else if(EM_INSTRUCTION_TYPE_FW == motionInstructionView->instructionStampTypeFlag)
        {
            motionInstructionView->instructionType = "FW";
        }
        else if(EM_INSTRUCTION_TYPE_FT == motionInstructionView->instructionStampTypeFlag)
        {
            motionInstructionView->instructionType = "FT";
        }
        else if(EM_INSTRUCTION_TYPE_FD == motionInstructionView->instructionStampTypeFlag)
        {
            motionInstructionView->instructionType = "FD";
        }
        else if(EM_INSTRUCTION_TYPE_D == motionInstructionView->instructionStampTypeFlag)
        {
            motionInstructionView->instructionType = "D";
        }
        else if(EM_INSTRUCTION_TYPE_DW == motionInstructionView->instructionStampTypeFlag)
        {
            motionInstructionView->instructionType = "DW";
        }
        else if(EM_INSTRUCTION_TYPE_DT == motionInstructionView->instructionStampTypeFlag)
        {
            motionInstructionView->instructionType = "DT";
        }
        else if(EM_INSTRUCTION_TYPE_DD == motionInstructionView->instructionStampTypeFlag)
        {
            motionInstructionView->instructionType = "DD";
        }

        //补充
        if(E_MOTION_J == motionInstructionView->instructionTypeFlag)
        {
            motionInstructionView->instructionType += "J";
        }
        else if(E_MOTION_L == motionInstructionView->instructionTypeFlag)
        {
            motionInstructionView->instructionType += "L";
        }
    }

    motionInstructionView->motionInstruction = motionInstructionView->instructionType + " "
            +motionInstructionView->positionTypeStr+"["+motionInstructionView->positionIndexAddressStr
            +"] "
            + QString("%1").arg(motionInstructionView->instructionRate)
            + motionInstructionView->rateUnit + " ";



    if("FINE" == motionInstructionView->instructionFixedPositionType)
    {
        motionInstructionView->motionInstruction += motionInstructionView->instructionFixedPositionType ;
    }
    else if("CNT" == motionInstructionView->instructionFixedPositionType)
    {
        motionInstructionView->motionInstruction += motionInstructionView->instructionFixedPositionType
                + QString::number(motionInstructionView->cntValue) ;
    }

    if(1 == motionInstructionView->isUseDiSkip)
    {
        //2017.05.16改动
        if(EM_INSTRUCTION_NORMAL == motionInstructionView->instructionMainFlag)
        {
            motionInstructionView->diInstruction = " DI";
            motionInstructionView->diInstruction += "[" + motionInstructionView->diIndex + "]" + " = "
                    + motionInstructionView->diSwitch + " Skip,LBL" + "[" + motionInstructionView->labelIndex + "]";
            motionInstructionView->motionInstruction += motionInstructionView->diInstruction ;
        }
        else
        {//下面格式不再使用
            motionInstructionView->diInstruction = " ,DI";//旧版本有逗号
            motionInstructionView->diInstruction += "[" + motionInstructionView->diIndex + "] == "
                    + motionInstructionView->diSwitch;
            motionInstructionView->motionInstruction += motionInstructionView->diInstruction ;
        }

    }
    if(1 == motionInstructionView->wjntFlag)
    {
        motionInstructionView->wjntInstruction = " Wjnt";
        motionInstructionView->motionInstruction += motionInstructionView->wjntInstruction ;
    }
    if(1 == motionInstructionView->incFlag)
    {
        motionInstructionView->incInstruction = " INC";
        motionInstructionView->motionInstruction += motionInstructionView->incInstruction ;
    }
    if(1 == motionInstructionView->accFlag)
    {
        motionInstructionView->accInstruction = " ACC" + QString::number(motionInstructionView->accValue);
        motionInstructionView->motionInstruction += motionInstructionView->accInstruction ;
    }
    if(1 == motionInstructionView->evFlag)
    {
        motionInstructionView->evInstruction = " EV" + QString::number(motionInstructionView->evValue) + "%";
        motionInstructionView->motionInstruction += motionInstructionView->evInstruction ;
    }
    if(1 == motionInstructionView->pthFlag)
    {
        motionInstructionView->pthInstruction = " PTH";
        motionInstructionView->motionInstruction += motionInstructionView->pthInstruction ;
    }
    if(1 == motionInstructionView->offsetFlag)
    {
        QString str = " Offset,";
        motionInstructionView->offsetInstruction = str + "PR" + "[" + motionInstructionView->offsetPrIndex + "]";
        motionInstructionView->motionInstruction += motionInstructionView->offsetInstruction ;
    }
    if(1 == motionInstructionView->toolOffsetFlag)
    {
        QString str = " Tool_Offset,";
        motionInstructionView->toolOffsetInstruction = str + "PR" + "[" + motionInstructionView->toolOffsetPrIndex + "]";
        motionInstructionView->motionInstruction += motionInstructionView->toolOffsetInstruction ;
    }

    motionInstructionView->motionInstruction = motionInstructionView->motionInstruction + "; "
            + "//" + motionInstructionView->moIns.comment;
}

void MotionInstructionDelegate::selectJInstructionSlot()
{
    motionInstructionView->instructionTypeFlag = E_MOTION_J;

    qDebug() << "select J instruction";
}

void MotionInstructionDelegate::selectLInstructionSlot()
{
    motionInstructionView->instructionTypeFlag = E_MOTION_L;

    qDebug() << "select L instruction";
}

void MotionInstructionDelegate::unlockPointSlot()
{
//    if(motionInstructionView->lockBtnText == tr("点已解锁"))
//    {
//        qDebug("锁定点");
//        motionInstructionView->lockBtnText = tr("点已锁定");
//        motionInstructionView->lockBtnPicture = "color: rgb(255, 255, 255); border-width:0px;border-style:outset;image: url(/agvwork/AgvHmi/baseBag/hmiProject/resources/instruction/MotionInstructionRes/empty_d.png);";
//    }
//    else if(motionInstructionView->lockBtnText == tr("点已锁定"))
//    {
//        qDebug("解锁点");
//        motionInstructionView->lockBtnText = tr("点已解锁");
//        motionInstructionView->lockBtnPicture = "color: rgb(255, 255, 255); border-width:0px;border-style:outset;image: url(/agvwork/AgvHmi/baseBag/hmiProject/resources/instruction/MotionInstructionRes/empty_n.png);";
//    }
    int index = motionInstructionView->pointProMo.pointNum-1;
    if(index<0)
    {
        return;
    }

    if(index < fileData.normalPointLock.size() )
    {
        if(fileData.normalPointLock[index])
        {
            fileData.normalPointLock[index] = false;
        }
        else
        {
            fileData.normalPointLock[index] = true;
        }
    }
    else
    {
        int size = fileData.normalPointLock.size();
        for(int i = size;i<=index;i++)
        {
            fileData.normalPointLock.append(false);
            if(i == index)
            {
                fileData.normalPointLock[index] = true;
            }
        }
    }

    motionInstructionView->updateView();
}

void MotionInstructionDelegate::recordPointSlot(int type,int pointNum)
{
    qDebug() << "MotionInstructionDelegate::recordPointSlot　";
    if((pointNum-1) < fileData.normalPointLock.size())
    {
        if(fileData.normalPointLock[pointNum-1])
        {
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("该点已被锁定,无法载入"));
            return;
        }
    }

    //PointPro tmpPoint;
    //motionInstructionView->pointProMo;
    //
    if(globalData)
    {
        PointPro currentPositionJointOut;
        globalData->getCurrentArmPosition_joint(currentPositionJointOut);
        PointPro currentPositionDecartOut;
        globalData->getCurrentArmPosition_decart(currentPositionDecartOut);
        int recordPointNum = pointNum;//motionInstructionView->pointProMo.pointNum;
        //获取当前点数据(判断当前是关节坐标还是世界坐标)
            if(globalData->getUserInfo().account < EM_ACCOUNT_ADMIN)
            {
                emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("您当前用户没有操作权限\n请切换用户角色"));
                return;
            }

            fileData.globalDefaultUserNum = globalData->globalDefaultUserNum;
            fileData.globalDefaultToolNum = globalData->globalDefaultToolNum;

            if(globalData->globalCoordinate == EM_JOG_COORDINATE_JOINT)
            {
                motionInstructionView->pointProMo.jointFlag = EM_CF_DEG_TYPE;
                motionInstructionView->pointProMo.pointNum = recordPointNum;
                motionInstructionView->pointProMo.groupNum = 0;
                motionInstructionView->pointProMo.ufValue = globalData->globalDefaultUserNum;
                motionInstructionView->pointProMo.utValue = globalData->globalDefaultToolNum;
                motionInstructionView->pointProMo.recordStatus = 0;
                //多圈 目前空
                motionInstructionView->pointProMo.configString = "";
                motionInstructionView->pointProMo.configInt.clear();
                //for(int i = 0;i < globalData->currentPositionJoint.configInt.size();i++)
                //{
                    //motionInstructionView->pointProMo.configInt.push_back(globalData->currentPositionJoint.configInt[i]);
                //}

                motionInstructionView->pointProMo.positionValue.clear();
                motionInstructionView->pointProMo.extPositionValue.clear();
                for(int i = 0;i < currentPositionJointOut.positionValue.size();i++)
                {
                    motionInstructionView->pointProMo.positionValue.push_back(currentPositionJointOut.positionValue[i]);//float
                    motionInstructionView->pointProMo.positionValue[i] = QString::number(motionInstructionView->pointProMo.positionValue[i],'f',3).toFloat();
                }
                for(int i = 0;i < currentPositionJointOut.extPositionValue.size();i++)
                {
                    motionInstructionView->pointProMo.extPositionValue.push_back(currentPositionJointOut.extPositionValue[i]);//float
                    motionInstructionView->pointProMo.extPositionValue[i] = QString::number(motionInstructionView->pointProMo.extPositionValue[i],'f',3).toFloat();
                }
            }
            else
            {
                motionInstructionView->pointProMo.jointFlag = EM_CF_WORLD_TYPE;//globalData->globalCoordinate;
                motionInstructionView->pointProMo.pointNum = recordPointNum;
                motionInstructionView->pointProMo.groupNum = 0;
                motionInstructionView->pointProMo.ufValue = globalData->globalDefaultUserNum;
                motionInstructionView->pointProMo.utValue = globalData->globalDefaultToolNum;
                motionInstructionView->pointProMo.recordStatus = 0;
                //多圈 目前空
                motionInstructionView->pointProMo.configString = currentPositionDecartOut.configString;
                motionInstructionView->pointProMo.configInt.clear();
                motionInstructionView->pointProMo.configInt = currentPositionDecartOut.configInt;

                motionInstructionView->pointProMo.positionValue.clear();
                motionInstructionView->pointProMo.extPositionValue.clear();
                for(int i = 0;i < currentPositionDecartOut.positionValue.size();i++)
                {
                    motionInstructionView->pointProMo.positionValue.push_back(currentPositionDecartOut.positionValue[i]);//float
                    motionInstructionView->pointProMo.positionValue[i] = QString::number(motionInstructionView->pointProMo.positionValue[i],'f',3).toFloat();
                }
                for(int i = 0;i < currentPositionJointOut.extPositionValue.size();i++)
                {
                    motionInstructionView->pointProMo.extPositionValue.push_back(currentPositionJointOut.extPositionValue[i]);//float
                    motionInstructionView->pointProMo.extPositionValue[i] = QString::number(motionInstructionView->pointProMo.extPositionValue[i],'f',3).toFloat();
                }
            }

        if(E_POSITION_P == type )//P点
        {
            if(fileData.getPointProList.size() == 0)
            {
                fileData.getPointProList.append(motionInstructionView->pointProMo);
            }
            else
            {
                //新判定 方法 支持动态增加多点
                //假设 当前有10个 添加 第15个点
                //下标0-9  实际编号1-10
                if(pointNum > fileData.getPointProList.size())
                {
                    int appendCount = pointNum - fileData.getPointProList.size();//15-10=5
                    int tmpPointNum = fileData.getPointProList.size();
                    for(int appendNum = 0;appendNum<appendCount;appendNum++)
                    {
                        tmpPointNum++;//11-15
                        motionInstructionView->pointProMo.pointNum = tmpPointNum;
                        fileData.getPointProList.append(motionInstructionView->pointProMo);//不断加
                    }
                }
                else
                {
                    //pointNumber-1 为数组下标
                    fileData.getPointProList.replace(pointNum-1,motionInstructionView->pointProMo);
                }
            }

            //刷新界面, 但数据是还没有保存的
            motionInstructionView->updateViewPointData();

            //保存文件
            fileData.writeProgramFile(fileData.currentFileName,true);
            emit setIsSaveSignal(false);
        }
        else if(E_POSITION_PR == type )//PR点
        {
            emit setPrSignal(pointNum-1,motionInstructionView->pointProMo);//下标
            //刷新界面, 但数据是还没有保存的
            motionInstructionView->updateViewPointData();
        }
    }
}

void MotionInstructionDelegate::moveToPointSlot(int type, int pointNumber)
{
    qDebug() << "move  to  point :" << pointNumber;

    if(E_POSITION_P == type)//P
    {
        //qDebug() << "point number :" << rx.cap(2);
        //int pointNumber = pointNumber;
        int arrayNumber = 0;//下标
        if(fileData.getPointProList.size() == 0)
        {
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前点没有载入点数据"));
            return;
        }
        //新判定 方法 支持动态
        if(pointNumber > fileData.getPointProList.size())
        {
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前点没有载入点数据"));
            return ;
        }
        else
        {
            arrayNumber = pointNumber-1;//该点存在,获取下标
        }

        MoveParameter tmpMoveParameter;
        tmpMoveParameter.moveType = 0;//默认关节方式移动

        tmpMoveParameter.targetPoint = fileData.getPointProList[arrayNumber];

        tmpMoveParameter.pointType = 0;//普通点

        //emit moveToPointSignal(tmpMoveParameter);
        //新方法
        moveOperation->startPointMove(tmpMoveParameter);
    }
    else if(E_POSITION_PR == type)//PR
    {
        std::vector<PointPro > pointRegisterOut;
        ioData->getPointRegister(pointRegisterOut);
        int arrayNumber = 0;//下标
        if(pointRegisterOut.size() == 0)
        {
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("PR寄存器没有点数据"));
            return;
        }

        //新判定 方法 支持动态
        if(pointNumber > pointRegisterOut.size())
        {
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("不存在该PR点数据"));
            return ;
        }
        else
        {
            arrayNumber = pointNumber-1;//该点存在,获取下标
        }
        //2017-04-13 补充判断:有无点数据
        if(pointRegisterOut[arrayNumber].positionValue.size()<=0)
        {
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前点没有载入点数据\n转换点前请先载入点"));
            return;
        }

        MoveParameter tmpMoveParameter;
        tmpMoveParameter.moveType = 0;//默认关节方式移动
        tmpMoveParameter.targetPoint = pointRegisterOut[arrayNumber];
        tmpMoveParameter.pointType = 0;//普通点
       moveOperation->startPointMove(tmpMoveParameter);
    }
    else
    {
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("码跺点类型不支持\n请在码跺工艺界面操作"));
        return;
    }
}

void MotionInstructionDelegate::moveToPointFinishSlot()
{
    qDebug() << "move to point finish";
    //emit stopMoveToPointSignal();
    //新方法
    moveOperation->stopPointMove();
}

void MotionInstructionDelegate::changePointToDegSlot(int pointNum)
{
    qDebug()<<"changePointToDegSlot:"<<pointNum;

//    for(int i = 0;i < fileData.getPointProList.size();i++)
//    {
//        if(fileData.getPointProList[i].pointNum == pointNum)
//        {
//            if(fileData.getPointProList[i].jointFlag == EM_CF_WORLD_TYPE)
//            {
//                emit changePointToDegCommSignal(fileData.getPointProList[i]);
//            }
//            break;//该点数据存在
//        }
//        else
//        {
//            //不存在该下标的当前点
//            if(i == fileData.getPointProList.size()-1)
//            {
//                emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前点没有载入点数据"));
//                return ;
//            }
//        }
//    }

    if(0 == motionInstructionView->positionTypeFlag)//P
    {
        //新判定 方法 支持动态
        if(pointNum > fileData.getPointProList.size())
        {
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前点没有载入点数据"));
        }
        else
        {
            if(fileData.getPointProList[pointNum-1].jointFlag == EM_CF_WORLD_TYPE)
            {
                emit changePointToDegCommSignal(fileData.getPointProList[ pointNum-1 ]);
            }
        }
    }
    else//PR
    {
        std::vector<PointPro > pointRegisterOut;
        ioData->getPointRegister(pointRegisterOut);
        //新判定 方法 支持动态
        if(pointNum > pointRegisterOut.size())
        {
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前点不存在"));
        }
        else
        {
            //2017-04-13 补充判断:有无点数据
            if(pointRegisterOut[pointNum-1].positionValue.size()<=0)
            {
                emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前点没有载入点数据\n转换点前请先载入点"));
                return;
            }

            if(pointRegisterOut[pointNum-1].jointFlag == EM_CF_WORLD_TYPE)
            {
                emit changePointToDegCommSignal(pointRegisterOut[ pointNum-1 ]);
            }
        }
    }

}

void MotionInstructionDelegate::changePointToWorldSlot(int pointNum)
{
    qDebug()<<"changePointToWorldSlot:"<<pointNum;

    if(0 == motionInstructionView->positionTypeFlag)//P
    {
        //新判定 方法 支持动态
        if(pointNum > fileData.getPointProList.size())
        {
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前点没有载入点数据"));
        }
        else
        {
            if(fileData.getPointProList[pointNum-1].jointFlag == EM_CF_DEG_TYPE)
            {
                emit changePointToWorldCommSignal(fileData.getPointProList[ pointNum-1 ]);
            }
        }
    }
    else
    {
        std::vector<PointPro > pointRegisterOut;
        ioData->getPointRegister(pointRegisterOut);
        if(pointNum > pointRegisterOut.size())
        {
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前点不存在"));
        }
        else
        {
            //2017-04-13 补充判断:有无点数据
            if(pointRegisterOut[pointNum-1].positionValue.size()<=0)
            {
                emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前点没有载入点数据\n转换点前请先载入点"));
                return;
            }

            if(pointRegisterOut[pointNum-1].jointFlag == EM_CF_DEG_TYPE)
            {
                emit changePointToWorldCommSignal(pointRegisterOut[ pointNum-1 ]);
            }
        }
    }

}

void MotionInstructionDelegate::inputPointTakeEffectSlot()
{
    qDebug() << "MotionInstructionDelegate::input point take effect 运动界面生效按钮按下槽函数" ;

    if(globalData)
    {
        if(0 == motionInstructionView->positionTypeFlag)
        {
            int recordPointNum = motionInstructionView->pointProMo.pointNum;

            //获取当前点数据
            if(fileData.getPointProList.size() == 0)
            {
                fileData.getPointProList.append(motionInstructionView->pointProMo);
            }
            else
            {

                //新判定 方法 支持动态增加多点
                //假设 当前有10个 添加 第15个点
                //下标0-9  实际编号1-10
                if(recordPointNum > fileData.getPointProList.size())
                {
                    int appendCount = recordPointNum - fileData.getPointProList.size();//15-10=5
                    int tmpPointNum = fileData.getPointProList.size();
                    for(int appendNum = 0;appendNum<appendCount;appendNum++)
                    {
                        tmpPointNum++;//11-15
                        motionInstructionView->pointProMo.pointNum = tmpPointNum;
                        fileData.getPointProList.append(motionInstructionView->pointProMo);//不断加
                    }
                }
                else
                {
                    //pointNumber-1 为数组下标
                    fileData.getPointProList.replace(recordPointNum-1,motionInstructionView->pointProMo);
                }
            }

            //刷新界面, 但数据是还没有保存的(手输入点 原本以为不需要刷新这个了,但测试发现不能去除)
            motionInstructionView->updateViewPointData();

            //保存文件
//             qDebug()<<fileData.cmdStrWriteList;
            fileData.writeProgramFile(fileData.currentFileName,true);

//            QString md5 = fileData.readProgramToMD5(fileData.currentFileName);
//            emit saveFileAndUpdateCtrlSignal(fileData.currentFileName,md5);
            emit setIsSaveSignal(false);
        }
        else
        {
            int recordPointNum = motionInstructionView->pointProMo.pointNum;

            emit setPrSignal(recordPointNum-1,motionInstructionView->pointProMo);//下标
        }
    }
}

void MotionInstructionDelegate::selectDiInstructionSlot(bool isUseIn)
{
        motionInstructionView->isUseDiSkip = isUseIn;
        qDebug() << "select DI instruction"<<isUseIn;
}

void MotionInstructionDelegate::clearNoteSlot()
{
    motionInstructionView->moIns.comment.clear();
    qDebug() << "clear note";
}

void MotionInstructionDelegate::selectWjntInstructionSlot()
{
    if(0 == motionInstructionView->wjntFlag)
    {
        motionInstructionView->wjntFlag = 1;
        qDebug() << "select Wjnt instruction";
    }
    else
    {
        motionInstructionView->wjntFlag = 0;
    }
}

void MotionInstructionDelegate::selectIncInstructionSlot()
{
    if(0 == motionInstructionView->incFlag)
    {
        motionInstructionView->incFlag = 1;
        qDebug() << "select INC instruction";
    }
    else
    {
        motionInstructionView->incFlag = 0;
    }
}

void MotionInstructionDelegate::selectAccInstructionSlot()
{
    if(0 == motionInstructionView->accFlag)
    {
        motionInstructionView->accFlag = 1;
        qDebug() << "select ACC instruction";
    }
    else
    {
        motionInstructionView->accFlag = 0;
    }
}

void MotionInstructionDelegate::selectOffsetInstructionSlot()
{
    if(0 == motionInstructionView->offsetFlag)
    {
        motionInstructionView->offsetFlag = 1;
        qDebug() << "select Offset instruction";
    }
    else
    {
        motionInstructionView->offsetFlag = 0;
    }
}

void MotionInstructionDelegate::selectToolOffsetInstructionSlot()
{
    if(0 == motionInstructionView->toolOffsetFlag)
    {
        motionInstructionView->toolOffsetFlag = 1;
        qDebug() << "select Tool_Offset instruction";
    }
    else
    {
        motionInstructionView->toolOffsetFlag = 0;
    }
}

void MotionInstructionDelegate::selectEvInstructionSlot()
{
    if(0 == motionInstructionView->evFlag)
    {
        motionInstructionView->evFlag = 1;
        qDebug() << "select EV instruction";
    }
    else
    {
        motionInstructionView->evFlag = 0;
    }
}

void MotionInstructionDelegate::selectPthInstructionSlot()
{
    if(0 == motionInstructionView->pthFlag)
    {
        motionInstructionView->pthFlag = 1;
        qDebug() << "select PTH instruction";
    }
    else
    {
        motionInstructionView->pthFlag = 0;
    }
}

void MotionInstructionDelegate::recvChangePointAndSave(PointPro recvPoint)
{
    //关节点和坐标点转换后再次保存。
    qDebug()<<"MotionInstructionDelegate::recvChangePointAndSave１";
    if(!motionInstructionView->isHidden())
    {
        qDebug()<<"MotionInstructionDelegate::recvChangePointAndSave２";

        if(globalData)
        {
            if(0 == motionInstructionView->positionTypeFlag)//P
            {
                int recordPointNum = recvPoint.pointNum;//motionInstructionView->pointProMo.pointNum;
                //获取当前点数据
//                motionInstructionView->pointProMo.jointFlag = recvPoint.jointFlag;
//                motionInstructionView->pointProMo.pointNum = recvPoint.pointNum;
//                motionInstructionView->pointProMo.groupNum = recvPoint.groupNum;
//                motionInstructionView->pointProMo.ufValue = recvPoint.ufValue;
//                motionInstructionView->pointProMo.utValue = recvPoint.utValue;
//                motionInstructionView->pointProMo.recordStatus = recvPoint.recordStatus;
//                motionInstructionView->pointProMo.configString = recvPoint.configString;
//                motionInstructionView->pointProMo.configInt = recvPoint.configInt;
//                motionInstructionView->pointProMo.positionValue = recvPoint.positionValue;
//                motionInstructionView->pointProMo.extPositionValue = recvPoint.extPositionValue;
                motionInstructionView->pointProMo = recvPoint;

                //qDebug()<<motionInstructionView->pointProMo.positionValue.size();
                if(fileData.getPointProList.size() == 0)
                {
                    fileData.getPointProList.append(motionInstructionView->pointProMo);
                }
                else
                {
                    //新判定 方法 支持动态增加多点
                    //假设 当前有10个 添加 第15个点
                    //下标0-9  实际编号1-10
                    if(recordPointNum > fileData.getPointProList.size())
                    {
                        int appendCount = recordPointNum - fileData.getPointProList.size();//15-10=5
                        int tmpPointNum = fileData.getPointProList.size();
                        for(int appendNum = 0;appendNum<appendCount;appendNum++)
                        {
                            tmpPointNum++;//11-15
                            motionInstructionView->pointProMo.pointNum = tmpPointNum;
                            fileData.getPointProList.append(motionInstructionView->pointProMo);//不断加
                        }
                    }
                    else
                    {
                        //pointNumber-1 为数组下标
                        fileData.getPointProList.replace(recordPointNum-1,motionInstructionView->pointProMo);
                    }
                }

                //刷新界面, 但数据是还没有保存的
                motionInstructionView->updateViewPointData();

                //保存文件
//                qDebug()<<fileData.cmdStrWriteList;
                fileData.writeProgramFile(fileData.currentFileName,true);

//                QString md5 = fileData.readProgramToMD5(fileData.currentFileName);
//                emit saveFileAndUpdateCtrlSignal(fileData.currentFileName,md5);
                emit setIsSaveSignal(false);
            }
            else//PR
            {
                int recordPointNum = recvPoint.pointNum;
                motionInstructionView->pointProMo = recvPoint;

                //io数据
                emit setPrSignal(recordPointNum-1,motionInstructionView->pointProMo);//下标);

                //刷新界面
                motionInstructionView->updateViewPointData();
            }
        }
    }
}
